package com.lqh.studyproject.jvmtest;

/**
 * @ClassName Test
 * @Description studyproject
 * @Author bgy-lqh
 * @Date 2020/7/1 17:35
 * @Version 测试demo
 **/
public class Test {
    public  int inc = 0;

    public synchronized void increase() {
        inc++;
    }

    public static void main(String[] args) {
        final Test test = new Test();
        for(int i=0;i<10;i++){
            new Thread(){
                @Override
                public void run() {
                    for(int j=0;j<1000;j++) {
                        test.increase();
                    }
                };
            }.start();
        }

        while(Thread.activeCount()>1) {  //保证前面的线程都执行完
            Thread.yield();
            System.out.println(test.inc);
        }
    }
}